package com.woniu.backstage.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniu.backstage.dao.TbFileMapper;
import com.woniu.backstage.entity.TbFile;
import com.woniu.backstage.entity.form.FileForm;
import com.woniu.backstage.service.ITbFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 文件表 服务实现类
 * </p>
 *
 * @author spirit
 * @since 2020-04-18
 */
@Service
public class TbFileServiceImpl extends ServiceImpl<TbFileMapper, TbFile> implements ITbFileService {
    @Autowired
    private TbFileMapper fileMapper;

    @Override
    public IPage<TbFile> pageLimit(Page<TbFile> page, FileForm fileForm) {
        QueryWrapper<TbFile> wrapper = new QueryWrapper<>();
        if(fileForm.getMd5() != null && fileForm.getMd5().length() > 0){
            wrapper.eq("md5",fileForm.getMd5());
        }
        wrapper.eq("status",0);
        IPage<TbFile> fileIPage = fileMapper.selectPage(page, wrapper);
        return fileIPage;
    }

    @Override
    public int updateFile(Serializable id) {
        return fileMapper.updateFile(id);
    }

    @Override
    public Integer deleteBatch(List<Integer> idArr) {
        return fileMapper.updateBatch(idArr);
    }

}
